home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C19 / DelayedInstantiation.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  576 b   |  32 lines

  1. //: C19:DelayedInstantiation.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Member functions of class templates are not
  7. // instantiated until they're needed.
  8.  
  9. class X {
  10. public:
  11.   void f() {}
  12. };
  13.  
  14. class Y {
  15. public:
  16.   void g() {}
  17. };
  18.  
  19. template <typename T> class Z {
  20.   T t;
  21. public:
  22.   void a() { t.f(); }
  23.   void b() { t.g(); }
  24. };
  25.  
  26. int main() {
  27.   Z<X> zx;
  28.   zx.a(); // Doesn't create Z<X>::b()
  29.   Z<Y> zy;
  30.   zy.b(); // Doesn't create Z<Y>::a()
  31. } ///:~
  32.